#!/usr/bin/env python
import os
import sys

print("Starting debug script...")

# 添加当前目录到Python路径
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, current_dir)
print(f"Added {current_dir} to Python path")

# 设置Django设置模块
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webmgr.settings')
print("Set DJANGO_SETTINGS_MODULE to webmgr.settings")

try:
    import django
    print(f"Django imported successfully, version: {django.get_version()}")
    
    # 初始化Django
    django.setup()
    print("Django setup successful")
    
    # 尝试导入视图
    from spideradmin.views import CrawlAPIView
    print("Views imported successfully")
    
    # 尝试运行服务器
    from django.core.management import execute_from_command_line
    print("Management commands available")
    
    # 尝试启动服务器
    print("Attempting to start server...")
    execute_from_command_line(['manage.py', 'runserver', '0.0.0.0:8000'])
    
except Exception as e:
    print(f"Error: {e}")
    import traceback
    traceback.print_exc() 